package anc.tankshooter.ui;

import org.andengine.engine.Engine;
import org.andengine.engine.camera.Camera;
import org.andengine.engine.handler.IUpdateHandler;
import org.andengine.entity.scene.Scene;
import org.andengine.opengl.util.GLState;
import org.andengine.opengl.vbo.VertexBufferObjectManager;


import anc.tankshooter.ui.SceneManager.SceneType;
import android.app.Activity;

public abstract class IScreen extends Scene 
{
    protected Engine mEngine;
    protected Activity mActivity;
    protected ResourcesManager mResourcesManager;
    protected VertexBufferObjectManager mVertextManager;
    protected Camera mCamera;
    protected boolean mIsPause;
    
    public IScreen()
    {
        this.mResourcesManager = ResourcesManager.getInstance();
        this.mEngine = mResourcesManager.mEngine;
        this.mActivity = mResourcesManager.mActivity;
        this.mVertextManager = mResourcesManager.mVertexManager;
        this.mCamera = mResourcesManager.mCamera;
        setBackgroundEnabled(false);
        createScene();
        registerUpdate();
    }
    
    private void registerUpdate(){
    	this.registerUpdateHandler(new IUpdateHandler(){

			@Override
			public void onUpdate(float second) {
				onUpdateScreen(second);
					
			}

			@Override
			public void reset() {
			}
    		
    	});
    }
    @Override
    protected void onManagedDraw(GLState pGLState, Camera pCamera) {
    	sortChildren(true);
    	super.onManagedDraw(pGLState, pCamera);
    }
    //---------------------------------------------
    // ABSTRACTION
    //---------------------------------------------
    
    /**
     * Khi màn hình này đc tạo.
     * 
     */
    protected abstract void createScene();
    
    /**
     * Hàm này gọi để đăng ký sự kiện update
     * tương đương với gameloop
     */
    public abstract void onUpdateScreen(float second);
    
    public abstract boolean onBackKeyPressed();
    
    public abstract SceneType getSceneType();
    
    public abstract void disposeScene();

}
